package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import stuff.DialogDisposeAction;

public class GUIDialogForString {
	
	private static GUIDialog dialog;
	
	public static void showMessage(JFrame parent, String showString, String title, int width) {
		dialog = new GUIDialog(parent);
		JPanel stringPanel = new JPanel(new BorderLayout());
		stringPanel.setOpaque(false);
		
		stringPanel.setBorder(new EmptyBorder(10,10 , 10, 10));
		JLabel lb = new JLabel(stringToWrapString(showString, width));
		stringPanel.add(lb,BorderLayout.CENTER);
		
		dialog.setTitle(title);
		
		JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
		JButton btExit = new CustomJButton("Ok", 100, 30, Color.white,
				CustomJButton.DARKER, Color.DARK_GRAY, 2, false, true);
		btExit.addActionListener(new DialogDisposeAction(dialog, parent));
		buttonPanel.add(btExit);
		stringPanel.add(buttonPanel,BorderLayout.SOUTH);
		dialog.setContentLayout(stringPanel);
		
		dialog.pack();
		dialog.setLocationRelativeTo(parent);
		dialog.setVisible(true);
	}
	
	public static String stringToWrapString(String string, int width){
		return "<html><body><p style='width: "+ width + "px;'>" + string + "</body></html>";
	}
	
}
